package com.abiao.shop.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description: CodeMsg
 * 返回的异常信息枚举 (./exception/GlobalException 有进一步封装)
 * @Author: AB
 * @Date: 2021-07-12
 * @Version:v1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CodeMsg {
    private int code;
    private String msg;

    //通用错误码 5001xx
    public static CodeMsg SUCCESS = new CodeMsg(0,"success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100,"服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101,"参数校验异常：%s");

    //登录模块 5002xx
    public static CodeMsg SESSION_ERROR = new CodeMsg(500210,"Session不存在或已失效");
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211,"密码不能为空");
    public static CodeMsg ACCOUNT_EMPTY = new CodeMsg(500212,"账号不能为空");
    public static CodeMsg USER_NOT_EXIST = new CodeMsg(500213,"该用户不存在");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500214,"密码错误");

    //商品模块  5003xx

    //订单模块  5004xx
    public static CodeMsg ORDER_EMPTY = new CodeMsg(500410,"您暂时没有订单");

    //秒杀模块  5005xx
    public static CodeMsg STOCK_ZERO = new CodeMsg(500510,"商品库存已卖光啦！！");
    public static CodeMsg SNAP_REPEAT = new CodeMsg(500511,"每种商品只能购买一次哦！！");
    public static CodeMsg LOGIN_LIMIT = new CodeMsg(500512,"用户未登录");
    public static CodeMsg ON_QUEUE = new CodeMsg(500513,"排队中");


    //参数补充
    public CodeMsg fillArgs(Object... args){
        int code = this.code;
        String msg = String.format(this.msg,args);
        return new CodeMsg(code,msg);
    }

}
